<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="spring" 	uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" 	uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c"		uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" 	uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" pageEncoding="utf-8"%>

<script type="text/javascript">
$(document).ready(function(){
	setMenuSelection("contracte");
    
	   
    $("#btContractsList").kendoButton({
        icon: "funnel"
    });

    $("#btContractsCard").kendoButton({
        icon: "plus"
    });
	
      $("#pRefDomains").kendoComboBox({
         index: -1,
         placeholder: "Selectaţi domeniu",
         dataTextField: "mdValue",
         dataValueField: "id",
         filter: "contains",
         change        : onSelectDomain,
         dataSource: {
             type: "json",
             transport: {
                 read: "json/listRefDomainsCBX"
             }
         }
     });    
     var domainsCB = $("#pRefDomains").data("kendoComboBox"); 
      
      $("#pRefServices").kendoComboBox({
          index: -1,
          placeholder: "Selectaţi serviciu",
          filter: "contains"	
      });
      var servicesCB = $("#pRefServices").data("kendoComboBox");
      
      $("#pRefPerson").kendoComboBox({
          index: -1,
          placeholder: "Selectaţi tipul persoanei",
          filter: "contains"
      });
      var personCB = $("#pRefPerson").data("kendoComboBox");
      
      
      
     
     function onSelectDomain(e) {
         //alert(this.value());
         //var dataItem = this.dataItem(e.item.index());
         //alert(combobox.value() );
         //javascript:window.open('adaugaContract?pDomain='+domainsCB.value(), target='_self');
    	 $("#pRefServices").kendoComboBox({dataSource: {
             type: "json",
             transport: {
                 read: {
                	 url: "json/listRefServicesByDomainCBX",
                	 data: { id: domainsCB.value() }
                 }
             }
         },
         index: -1,
		 value: "",
         dataTextField: "mdValue",
         dataValueField: "id",
         placeholder: "Selectaţi serviciu",
         change        : onSelectService
         });
    	 
     };
     
     function onSelectService(e) {
//     	 alert('Service selected');
    	 $("#pRefPerson").kendoComboBox({
    		    index: -1,
    		    value: "",
    		    dataTextField: "name",
    		    dataValueField: "id",
    		    placeholder: "Selectaţi tipul persoanei",
    		    dataSource: [
    		        { name: "Persoana fizică", id: 1 },
    		        { name: "Persoana juridică", id: 2 }
    		    ],
    	          change        : onSelectPerson
    		});
    	 
     };
     
     function onSelectPerson(e) {
    	 //alert('Person selected');
//     	 if (domainsCB.value()==1){
//     	 javascript:window.open('adaugaContractFinBank?pDomain='+domainsCB.value()+'&pService='+servicesCB.value()+'&pPerson='+personCB.value(), target='_self');
//     	 };
		switch (domainsCB.value()) {
		   case "1":
			   javascript:window.open('adaugaContractFinBank?pDomain='+domainsCB.value()+'&pService='+servicesCB.value()+'&pPerson='+personCB.value(), target='_self');
		      break;
		   case "2":
			   if (personCB.value()==2){
			   		javascript:window.open('adaugaContractMM?pDomain='+domainsCB.value()+'&pService='+servicesCB.value()+'&pPerson='+personCB.value(), target='_self');
			   }
		      break;
		   case "3":
			   //if (personCB.value()==1){
			   		javascript:window.open('adaugaContractImob?pDomain='+domainsCB.value()+'&pService='+servicesCB.value()+'&pPerson='+personCB.value(), target='_self');
			   //}
			  break;
		   case "6":
			   if (personCB.value()==2){
			   		javascript:window.open('adaugaContractEvCont?pDomain='+domainsCB.value()+'&pService='+servicesCB.value()+'&pPerson='+personCB.value(), target='_self');
			   }   
		      break;
		   case "4":
			   //if (personCB.value()==2){
			   		javascript:window.open('adaugaContractAsig?pDomain='+domainsCB.value()+'&pService='+servicesCB.value()+'&pPerson='+personCB.value(), target='_self');
			   //}   
		      break;   
		}
     };
     
//      function getParameter(paramName) {
//     	  var searchString = window.location.search.substring(1),
//     	      i, val, params = searchString.split("&");

//     	  for (i=0;i<params.length;i++) {
//     	    val = params[i].split("=");
//     	    if (val[0] == paramName) {
//     	      return unescape(val[1]);
//     	    }
//     	  }
//     	  return null;
//     	};
    
// 	if (getParameter("pDomain")!=null){
// 		domainsCB.value(3);
// 	};
    
// 	$("#btCCard").on("click", function() {
//     	domainsCB.value(3);
//     });
    
});


function SubmitFormPersonsCard(pPostOperation){
	var formAction = $("#formPersonsCard").attr( 'action' );
	$("#formPersonsCard").attr('action', formAction + '?pPostOperation='+pPostOperation);
	$("#formPersonsCard").submit();
}


</script>

<CENTER>
<p style="text-align: left;">
<!-- 	<button id="btContractsList" type="button" onclick="javascript:window.open('vizualizeazaContracte', target='_self')";>Lista contractelor</button> -->
<!-- 	<button id="btContractsCard" type="button" onclick="javascript:window.open('adaugaContract', 		target='_self')";>Adaugă contract</button> -->
	
	<c:if test="${errorMessage != '' &&  errorMessage != '0'}">
		<span id="errorMessage" class="errorMessage"> ${errorMessage} </span>
	</c:if>
	
</p>
<p>
	<label  for="pRefDomains" class="required" >Domenii de activitate:   </label> 
	<select id="pRefDomains"  style="width:300px;" >
	</select>	
</p>	
<p>	
	<label  for="pRefServices" class="required" >Servicii:   </label>
	<select id="pRefServices" style="width:300px;"  >
	</select>	
</p>
<p>	
	<label  for="pRefPerson" class="required" >Persoana fizică sau juridică:   </label>
	<select id="pRefPerson" style="width:300px;"  >
	</select>	
</p>
    
</CENTER>
<style scoped>
     #formPersonsCard ul {
         list-style-type: none;
         margin: 0;
         padding: 0;
     }
     #formPersonsCard li {
         margin: 10px 0 0 0;
     }

     label {
         display: inline-block;
         width: 300px;
         text-align: right;
     }
     
     input {
     	height: 10px;
     }

     .required {
         font-weight: bold;
     }

     .accept, .status {
         padding-left: 90px;
     }

     .valid {
         color: green;
     }

     .invalid {
         color: red;
     }
     span.k-tooltip {
         margin-left: 6px;
     }
 </style>



